//
//  BCTitleTextFieldView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/29.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCTitleTextFieldView.h"

//titleLabel的固定高度
static CGFloat BCTitleTextFieldViewTitleHeight = 30.0;
//title与textField间隔
static CGFloat BCTitleTextFieldViewTitleTextFieldPadding = 5.0;
//textField高度
static CGFloat BCTitleTextFieldViewTextFieldHeight = 35.0;

@implementation BCTitleTextFieldView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupSubviews];
    }
    return self;
}
- (void)setupSubviews {
    _titleLabel = [QMUILabel new];
    _titleLabel.textColor = [UIColor qmui_colorWithHexString:@"#333333"];
    _titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
    _textField.adjustsFontSizeToFitWidth = true;
    [self addSubview:self.titleLabel];
    
    
    _textField = [QMUITextField new];
    _textField.textColor = _titleLabel.textColor;
    _textField.tintColor = _textField.textColor;
    _textField.placeholderColor = [UIColor qmui_colorWithHexString:@"#D6D6D6"];
    _textField.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    _textField.adjustsFontSizeToFitWidth = true;
    _textField.textInsets = UIEdgeInsetsZero;
    _textField.autocorrectionType = UITextAutocorrectionTypeNo;
    _textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    [self addSubview:self.textField];
    //
    _textField.inputAccessoryView = [UIView new];
    
    _bottomLine = [UIView new];
    _bottomLine.backgroundColor = [UIColor separatorColor];
    [self addSubview:self.bottomLine];
    
    //layout
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(20.0);
        make.top.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-20.0);
        make.height.mas_equalTo(BCTitleTextFieldViewTitleHeight);
    }];
    //
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(20.0);
        make.bottom.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-20.0);
        make.height.mas_equalTo(BCTitleTextFieldViewTextFieldHeight);
    }];
    //
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(10.0);
        make.right.mas_equalTo(self).offset(-10.0);
        make.height.mas_equalTo(1.0);
        make.bottom.mas_equalTo(self);
    }];
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}
- (void)setPlaceholder:(NSString *)placeholder {
    _placeholder = placeholder;
    //
    self.textField.placeholder = placeholder;
}



+ (CGFloat)defaultHeight {
    CGFloat height = 0;
    height += BCTitleTextFieldViewTitleHeight;
    height += BCTitleTextFieldViewTitleTextFieldPadding;
    height += BCTitleTextFieldViewTextFieldHeight;
    return height;
}
@end
